***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB311"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.3.11 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property" 
global ctrl_plus	"mean_votation lcrSR_F_N"
global fe			"charact_agglo"
global fe_iv		"I_charact_agglo_*"
global cluster		"charact_agglo"

// Column 1
		
reghdfe oui instr_dev_rs3_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_rs3dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store RF_rs3_dev_ctrl

// Column 2

reghdfe endog_mk instr_dev_rs3_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_rs3dstr==1, ///
	absorb($fe) cluster($cluster) keepsing
estimates store FS_rs3_dev_ctrl
test instr_dev_rs3_mk
estadd scalar F_fs=r(F)
	
// Column 3
		
ivreg2 oui (endog_mk = instr_dev_rs3_mk) ///
	$ctrl_plus ///
	$ctrl_base ///
	$fe_iv ///
	if sample_rs3dstr==1, ///
	cluster($cluster) first partial($fe_iv)	
estimates store TSLS_rs3_dev_ctrl

// Column 4
		
reghdfe oui instr_dev_rs3_mk instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_rs3dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
estimates store RF_rs3_dev_ctrl_main

// Column 5

reghdfe endog_mk instr_dev_rs3_mk instr_dev_mk /// 		
	$ctrl_plus ///
	$ctrl_base ///
	if sample_rs3dstr==1, ///
	absorb($fe) cluster($cluster) keepsing
estimates store FS_rs3_dev_ctrl_main
test instr_dev_rs3_mk instr_dev_mk
estadd scalar F_fs=r(F)
	
// Column 6
		
ivreg2 oui (endog_mk = instr_dev_rs3_mk instr_dev_mk) ///
	$ctrl_plus ///
	$ctrl_base ///
	$fe_iv ///
	if sample_rs3dstr==1, ///
	cluster($cluster) first partial($fe_iv)	
estimates store TSLS_rs3_dev_ctrl_main

// Labels

la var endog_mk 			"Crime News Exposure ($ \mathtt{CNE} $)"
la var instr_dev_rs3_mk 	"[0.1em] Top Readershare $ \mathtt{CPD} $ Deviation"
la var instr_dev_mk 		"[0.1em] HQ $ \mathtt{CPD} $ Deviation ($ \mathtt{\Delta HQC} $)"
la var lcrSR_F_N			"[0.1em] Local $ \mathtt{CPD} $"
la var mean_votation 		"[0.1em] Past Vote Outcomes"

// Table

estout RF_rs3_dev_ctrl FS_rs3_dev_ctrl TSLS_rs3_dev_ctrl  RF_rs3_dev_ctrl_main FS_rs3_dev_ctrl_main TSLS_rs3_dev_ctrl_main ///
	using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
	stats(N r2_a F_fs, lab("Observations" "Adjusted $ R^2 $" "First-stage F-statistic") fmt(0 3 2)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_mk lcrSR_F_N mean_votation instr_dev_rs3_mk instr_dev_mk) /// 
	order(endog_mk lcrSR_F_N mean_votation instr_dev_rs3_mk instr_dev_mk) ///	
	title(News and voting: Instrument with crime in places with large readershare) ///	
	prehead("\begin{table}[!h]" ///
	"\centering" ///
	"\resizebox {1\textwidth}{!}{%" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///
	"\\" ///
	"Instrument			&\multicolumn{3}{c}{Top Readershare $ \mathtt{CPD} $ Deviation} 	&\multicolumn{3}{c}{(i) Top Readershare $ \mathtt{CPD} $ Deviation} \\" ///
	"					&\multicolumn{3}{c}{ } 										&\multicolumn{3}{c}{(ii) HQ $ \mathtt{CPD} $ Deviation ($ \mathtt{\Delta HQC} $)} \\" ///
	"					\cmidrule(lr){2-4} \cmidrule(lr){5-7}	" ///
	"Specification		&\multicolumn{1}{c}{RF}			&\multicolumn{1}{c}{FS}			&\multicolumn{1}{c}{2SLS}		&\multicolumn{1}{c}{RF}		&\multicolumn{1}{c}{FS}		&\multicolumn{1}{c}{2SLS} \\" ///
	"					\cmidrule(lr){2-2} 				\cmidrule(lr){3-4}				\cmidrule(lr){5-5}				\cmidrule(lr){6-7}" ///
	"Dependent Variable &\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes}	&\multicolumn{1}{c}{\%Yes} 		&\multicolumn{1}{c}{$ \mathtt{CNE} $}		&\multicolumn{1}{c}{\%Yes} \\" ///
	"					\cmidrule(lr){2-2}				\cmidrule(lr){3-4} 	\cmidrule(lr){5-5}				\cmidrule(lr){6-7} 	 " ///
	"					&\multicolumn{1}{c}{(1)} 		&\multicolumn{1}{c}{(2)}  		&\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)} 		&\multicolumn{1}{c}{(5)}  		&\multicolumn{1}{c}{(6)} \\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot("\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"The unit of observation is a municipality. " ///
	"Standard errors clustered at agglomeration level in parentheses. " ///
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " ///
	"Columns (1) to (3) show estimates with the instrument for $ \mathtt{CNE} $ computed as short-run deviation of $ \mathtt{CPD} $ in the top-5 readership municipalities of each newspaper" ///
	"(instead of the headquarter municipalites of each newspaper in our baseline specification)." ///
	"Columns (4) to (6) present estimates where $ \mathtt{CNE} $ is instrumented by both our baseline instrument ($ \mathtt{\Delta HQC} $)" ///
	"and the instrument computed on the top-5 readership municipalities of each newspaper." ///
	"All regressions include the full vector of controls of Table \ref{Main_Table2}. " ///
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}}" ///
	"\end{table}")

cap log close
